﻿using System;
using System.Collections;

namespace Noea.TogSim.Model.Interfaces
{
    public delegate void BlockHandler(ITrack track, ITrackEventArgs e);
    public delegate void TrackChangeHandler(ITrack track, ITrackEventArgs e);

    public interface ITrack
    {
        //	Properties
        /// <summary>
        /// Identification of the track
        /// </summary>
        int Id { get; }
        /// <summary>
        /// Indicates that a train set is on the track
        /// </summary>
        bool IsBlocked { get; set; }
        /// <summary>
        /// Length of the track. For curved track, it is the middle line. Det er det osse for lige spor ;o)
        /// </summary>
        double Length { get; set; }
        /// <summary>
        /// Angle of the arc. For straight _trackRows, it is 0.
        /// </summary>
        double Angle { get; set; }
        /// <summary>
        ///  Next track. Undependent of the trains driving direction. For blind ends it is null. 
        /// </summary>
        ITrack Next { get; set; }
        /// <summary>
        ///  Previous track. Undependent of the trains driving direction. For blind ends it is null
        /// </summary>
        ITrack Previous { get; set; }
        /// <summary>
        /// List of next tracks
        /// </summary>
        ITrack[] NextList { get; }
        /// <summary>
        /// List of previous tracks
        /// </summary>
        /// 

        ITrack[] PreviousList { get; }
        /// <summary>
        /// Train, that is blocking the track
        /// </summary>
        ITrainSet Train { get; set; }
        /// <summary>
        /// Collection of signals, that is attached to the track
        /// </summary>
        IList Signals { get; }
        /// <summary>
        /// Collection of sensors, that is attached to the track
        /// </summary>
        IList Sensors { get; }

        //	Method
        /// <summary>
        /// Get next track, dependent of train driving direction. For blind ends it is null.
        /// </summary>
        /// <param name="previousTrack"></param>
        /// <returns>Next track in driving direction</returns>
        ITrack GetNext(ITrack previousTrack);

        /// <summary>
        /// Attach signal to the track. The signal is notified when IsBlocked changes
        /// </summary>
        /// <param name="s">The signal to be attached</param>
        void AddSignal(ISignal s);
        /// <summary>
        /// Remove signal from track
        /// </summary>
        /// <param name="s">Signal to be removed</param>
        void RemoveSignal(ISignal s);
        /// <summary>
        /// Remove signal from track
        /// </summary>
        /// <param name="index">Position of signal to be removed</param>
        void RemoveSignal(int index);
        /// <summary>
        /// Get signal at position
        /// </summary>
        /// <param name="index">Position</param>
        /// <returns>Signal at position</returns>
        ISignal GetSignal(int index);
        event BlockHandler OnBlock;
        event TrackChangeHandler OnChange;
    }

    public interface ITrackEventArgs
    {
        ITrack Track { get; }
        Object OldValue { get; }
        Object NewValue { get; }
    }
}
